package sig.web.struts.actions;

import sig.model.entities.BusinessPartner;
import sig.model.entities.Customer;
import sig.util.IServices;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class BusinessPartnerAction extends ActionSupport implements
		ModelDriven<BusinessPartner> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private BusinessPartner businessPartner = new BusinessPartner();
	private IServices services;

	public String execute() {
		return SUCCESS;
	}

	@Override
	public BusinessPartner getModel() {

	
		return businessPartner;
	}

	public String save() {
		Customer customer;
		switch (businessPartner.getType()) {
		case cliente:

			customer = new Customer();
			customer.setAdress(businessPartner.getAdress());
			customer.setCode(businessPartner.getCode());
			customer.setName(businessPartner.getName());
			customer.setRfc(businessPartner.getRfc());
			customer.setStatus(businessPartner.getStatus());
			customer.setType(businessPartner.getType());
			services.saveBusinessPartner(customer);

			break;

		case leeds:

			break;

		case proveedor:

			break;

		default:
			
			services.saveBusinessPartner(businessPartner);
			
			break;
		}
		return SUCCESS;
	}

	public IServices getServices() {
		return services;
	}

	public void setServices(IServices services) {
		this.services = services;
	}

}
